package com.ziyun.erp.web.modules.goodsConfigChangePrice.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.goodsConfigChangePrice.entity.GoodsConfigChangePriceEntity;
import com.ziyun.erp.modules.goodsConfigChangePrice.service.GoodsConfigChangePriceService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 变价记录表（erp）
 *
 * @author xueqz
 * @email 
 * @date 2018-09-18 10:05:20
 */
@RestController
@RequestMapping("goodsConfigChangePrice/goodsconfigchangeprice")
public class GoodsConfigChangePriceController {
    @Autowired
    private GoodsConfigChangePriceService goodsConfigChangePriceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("goodsConfigChangePrice:goodsconfigchangeprice:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsConfigChangePriceService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("goodsConfigChangePrice:goodsconfigchangeprice:info")
    public R info(@PathVariable("id") Long id){
        GoodsConfigChangePriceEntity goodsConfigChangePrice = goodsConfigChangePriceService.selectById(id);

        return R.ok().put("goodsConfigChangePrice", goodsConfigChangePrice);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("goodsConfigChangePrice:goodsconfigchangeprice:save")
    public R save(@RequestBody List<GoodsConfigChangePriceEntity> goodsConfigChangePriceList){
        goodsConfigChangePriceService.insertBatch(goodsConfigChangePriceList);
//        goodsConfigChangePriceService.insert(goodsConfigChangePrice);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("goodsConfigChangePrice:goodsconfigchangeprice:update")
    public R update(@RequestBody GoodsConfigChangePriceEntity goodsConfigChangePrice){
        ValidatorUtils.validateEntity(goodsConfigChangePrice);
        goodsConfigChangePriceService.updateAllColumnById(goodsConfigChangePrice);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("goodsConfigChangePrice:goodsconfigchangeprice:delete")
    public R delete(@RequestBody Long[] ids){
        goodsConfigChangePriceService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
